# coding=utf-8
import logging
import os
import subprocess


def shell_cmd(cmd):
    logging.debug("Exe cmd: %s" % cmd)
    # result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    # for info in result.communicate():
    #     logging.debug(info)
    return os.system(cmd)


def shell_cmd_with_ret(cmd, strip=True):
    logging.debug("Exe cmd with ret: %s" % cmd)
    sub_p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    ret = sub_p.stdout.read()
    msg = sub_p.stderr.read()
    logging.debug("ret=%s msg=%s" % (ret, msg))
    if strip:
        return ret.strip(), msg.strip()
    return ret, msg
